<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="format-detection" content="email=no"/>
    <meta charset="UTF-8">
    <script type="text/javascript" th:src="@{${session.baseUrl}+'js/common.js'}"></script>
    <script th:src="@{${session.baseUrl}+'js/jquery.js'}"></script>
    <script th:src="@{${session.baseUrl}+'js/dialog.js'}"></script>
    <link th:href="@{${session.baseUrl}+'style/dialog.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/reset.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/base.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/header.css'}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" th:href="@{${session.baseUrl}+'style/withdraw.css'}"/>
    <link rel="stylesheet" th:href="@{${session.baseUrl}+'style/personal.css'}"/>
    <title>提现</title>
</head>
<body>
<header><span onclick="javascript:history.go(-1)"></span>提现</header>
<ul class="bgwh content1">
    <li class="df pr30 pl30">
        <label class="f26" for="bank">提现方式</label>
        <select name="bank" id="bank" class="background" onchange="disp()">
            <option value="0"><p>请选择提现方式</p></option>
            <option value="1"><p>提现到支付宝</p></option>
            <option value="2"><p>提现到微信</p></option>
            <option value="3"><p>提现到银行卡</p></option>
        </select>
    </li>
    <li class="df pr30 pl30"><label class="f26" for="id">可提现金额</label><input type="text" id="id" th:value="${wallet.balance}" disabled/></li>
    <li class="pr30 pl30" style="background: none">
        <label class="f26" for="money">本次提现金额</label>
        <input type="text" id="money" placeholder="请输入提现金额" style="margin-right: 0.5rem;"/>元
    </li>
    <li class="pr30 pl30" style="display: none;" id="accounts1"><label class="f26" for="money">支付宝帐号：</label><input type="text" id="aliAccounts" th:value="${user.aliAccount}"/></li>
    <li class="pr30 pl30" style="display: none" id="accounts2"><label class="f26" for="money">微信帐号：</label><input ype="text" id="wxAccounts" th:value="${user.wechatAccount}"/></li>
    <li class="pr30 pl30" style="display: none" id="accounts3"><label class="f26" for="money">银行卡帐号：</label><input ype="text" id="bankAccounts" th:value="${user.bankAccount}"/></li>
    <li style="background: #f2f2f2;" id="accountsSpan"></li>
</ul>
<p style="margin-top: 20px;color:red;font-size: 0.4rem;font-weight: bold;margin-bottom: 0.2rem;">众财经提醒您：</p>
<p style="color: red;font-weight: bold;margin-bottom: 0.1rem;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请再三确认您的帐号无误，我们将向该账户转账。</p>
<p style="color: red;font-weight: bold;margin-bottom: 0.1rem;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果账户有误，我们将不退还款项。</p>
<p style="color: red;font-weight: bold;margin-bottom: 0.1rem;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;因提现需转账，所提每次提现会收取5元手续费</p>
<input type="submit" value="确认提现"  onclick="check()" id="btn"/>
<input type="submit" value="全额提现"  onclick="checkall()" id="btnall"/>
<div style="margin-top: 20px; margin-left: 120px;"><span id="moneySpan" style="font-size: 17px;"></span></div>

<input type="hidden" th:value="${memberId}" id="memberId">
<div class="am-share1" style="display: none">
    <h3 class="am-share-title1 tc">确认帐号无误？</h3>
    <div class="df jcsb aic"><button class="share_btn1 yes" onclick="buy()">是</button><button class="share_btn1">否</button></div>
</div>
<script>
    $(function () {
        $("select").change(function () {
            if ($(this).val() != "default") {
                $(this).css("paddingLeft", "0.68rem");
            } else {
                $(this).css("paddingLeft", "0");
            }
            switch ($(this).val()) {
                case "工行":
                    $(this).css("backgroundImage", "url(http://localhost:8050/crowd-wap/images/bank.png)");
                    break;
                default :
                    $(this).css("backgroundImage", "url()");
                    break;
            }
        });
    });

    /**
     * 控制显示支付宝或者微信的输入帐号
     */
    function disp() {
        var a = $("#bank option:selected").val();
        if (a == 0){
            document.getElementById("accounts1").style.display = "none";
            document.getElementById("accounts2").style.display = "none";
            document.getElementById("accounts3").style.display = "none";
        }
        if (a == 1) {
            document.getElementById("accounts1").style.display = "inline";
            document.getElementById("accounts2").style.display = "none";
            document.getElementById("accounts3").style.display = "none";
        }
        if (a == 2) {
            document.getElementById("accounts1").style.display = "none";
            document.getElementById("accounts2").style.display = "inline";
            document.getElementById("accounts3").style.display = "none";
        }
        if (a == 3) {
            document.getElementById("accounts1").style.display = "none";
            document.getElementById("accounts2").style.display = "none";
            document.getElementById("accounts3").style.display = "inline";
        }
    }


    var money1 = parseInt($("#money").val());
    var aliAccounts1 =  $('#aliAccounts').val();
    var wxAccounts1 =  $('#wxAccounts').val();
    var bankAccounts1 =  $('#bankAccounts').val();
    var a1 = $("#bank option:selected").val();
    /**
     * 验证金额是否正确，正确则生成提现申请
     */
    function check() {
        var money = parseInt($("#money").val());
        var banlance = parseInt($("#id").val());
        var aliAccounts =  $('#aliAccounts').val();
        var wxAccounts =  $('#wxAccounts').val();
        var bankAccounts =  $('#bankAccounts').val();
        var a = $("#bank option:selected").val();
        money1 = money;
        aliAccounts1 = aliAccounts;
        wxAccounts1 = wxAccounts;
        bankAccounts1 = bankAccounts;
        a1 = a;
        if (a == 0){
            $("#moneySpan").html('请选择提现方式！').css('color', '#ff2525');
            return false;
        } else if (a == 1 && aliAccounts == ""){
            $("#accountsSpan").html('请输入支付宝帐号！').css('color', '#ff2525');
            return false;
        } else if (a == 2 && wxAccounts == ""){
            $("#accountsSpan").html('请输入微信帐号！').css('color', '#ff2525');
            return false;
        } else if (a == 3 && bankAccounts == ""){
            $("#accountsSpan").html('请输入银行卡帐号！').css('color', '#ff2525');
            return false;
        }else {
            $("#accountsSpan").html('');
        }
        if (money % 100 != 0) {
            $("#moneySpan").html('只能输入整百金额！').css('color', '#ff2525');
            return false;
        } else if (money <= 0) {
            $("#moneySpan").html('请输入正确的金额！').css('color', '#ff2525');
            return false;
        } else if (money > banlance) {
            $("#moneySpan").html('账户余额不足！').css('color', '#ff2525');
            return false;
        } else {
            var self=$("#btn");
            $(".am-share1").css("display","block");
            if($(".sharebg1").length>0){
                $(".sharebg1").addClass("sharebg-active1");
            }else{
                $("body").append('<div class="sharebg1"></div>');
                $(".sharebg1").addClass("sharebg-active1");
            }
            document.documentElement.style.overflow='hidden';
            document.body.style.overflow='hidden';
            $(".share_btn1").click(function(){
                if($("#btn").hasClass("yes")){
                    self.parents("li").remove();
                }
                $(".am-share1").css("display","none");
                setTimeout(function(){
                    $(".sharebg1").remove();
                },300);
                document.documentElement.style.overflow='auto';
                document.body.style.overflow='auto';
            })
        }
    }

    /**
     * 验证金额是否正确，正确则生成提现申请
     */
    function checkall() {

        var banlance = $("#id").val();
        $("#money").val(banlance)
        var aliAccounts =  $('#aliAccounts').val();
        var wxAccounts =  $('#wxAccounts').val();
        var bankAccounts =  $('#bankAccounts').val();
        var a = $("#bank option:selected").val();
        var money = $("#money").val();
        money1 = money;
        aliAccounts1 = aliAccounts;
        wxAccounts1 = wxAccounts;
        bankAccounts1 = bankAccounts;
        a1 = a;
        if (a == 0){
            $("#moneySpan").html('请选择提现方式！').css('color', '#ff2525');
            return false;
        } else if (a == 1 && aliAccounts == ""){
            $("#accountsSpan").html('请输入支付宝帐号！').css('color', '#ff2525');
            return false;
        } else if (a == 2 && wxAccounts == ""){
            $("#accountsSpan").html('请输入微信帐号！').css('color', '#ff2525');
            return false;
        } else if (a == 3 && bankAccounts == ""){
            $("#accountsSpan").html('请输入银行卡帐号！').css('color', '#ff2525');
            return false;
        }else {
            $("#accountsSpan").html('');
        }
         if (money <= 0) {
            $("#moneySpan").html('请输入正确的金额！').css('color', '#ff2525');
            return false;
        } else if (money > banlance) {
            $("#moneySpan").html('账户余额不足！').css('color', '#ff2525');
            return false;
        } else {
            var self=$("#btnall");
            $(".am-share1").css("display","block");
            if($(".sharebg1").length>0){
                $(".sharebg1").addClass("sharebg-active1");
            }else{
                $("body").append('<div class="sharebg1"></div>');
                $(".sharebg1").addClass("sharebg-active1");
            }
            document.documentElement.style.overflow='hidden';
            document.body.style.overflow='hidden';
            $(".share_btn1").click(function(){
                if($("#btnall").hasClass("yes")){
                    self.parents("li").remove();
                }
                $(".am-share1").css("display","none");
                setTimeout(function(){
                    $(".sharebg1").remove();
                },300);
                document.documentElement.style.overflow='auto';
                document.body.style.overflow='auto';
            })
        }
    }



    /**
     * 提现申请
     */
    function buy() {
        if (a1 == 1){
            wxAccounts1 = "";
            bankAccounts1 = "";
        }
        if (a1 == 2){
            aliAccounts1 = "";
            bankAccounts1 = "";
        }
        if (a1 == 3){
            aliAccounts1 = "";
            wxAccounts1 = "";
        }
        $("#moneySpan").html('');
        $.ajax({
            url: "/cashWithdrawal/add2",
            contentType: 'application/json',
            type: "POST",
            dataType: "json",
            data: JSON.stringify({
                aliAccounts: aliAccounts1,
                wxAccounts: wxAccounts1,
                bankAccount:bankAccounts1,
                money: money1,
                memberId: $('#memberId').val(),
                status: 0,
            }),
            success: function (e) {
                if(e.data==500){
                    $('body').dailog({type:'danger',title:'提示',discription:'您的可用余额已不足扣除手续费！'});
                    self.setInterval(function(){  // 这个方法是说在延迟3秒后执行大括号里的方法
                        location.reload();
                    },3000) //这里3000代表3秒
                }
                if (e.data) {
                    $('body').dailog({type: 'success', discription: '已提交申请，等待管理员审核后将您的资金转入您的账户'});
                    self.setInterval(function () {  // 这个方法是说在延迟3秒后执行大括号里的方法
                        location.reload();   // 这个方法是刷新当前页面
                    }, 4000) //这里3000代表3秒
                }
            }
        })
    }
</script>
</body>
</html>